﻿using System.Linq;
using UniMana.Utils.Controls;
using UniMana.Data;
using System;
using UniMana.Utils.Configs;

namespace UniMana.Data
{
    public class Personnel_Personnel_SubjectRegistInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }
        #endregion /*Không thay đổi*/

        private DBMain m_data = new DBMain();
        #region [Properties - Thuộc tính]
        public Personnel_Personnel_SubjectRegist Properties
        {
            get { return m_bds.Current as Personnel_Personnel_SubjectRegist; }
        }
        #endregion

        public Personnel_Personnel_SubjectRegistInfo(int m_iDefaultKey = 0, string value = "", int valu = 0)
        {
            var IQuery = m_data.m_DCSave.Personnel_Personnel_SubjectRegists.Where(tb => tb.Personnel_Personnel_SubjectRegistKey == m_iDefaultKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Personnel_Personnel_SubjectRegist();
                m_bds.Add(Row);
            }
        }

        public Personnel_Personnel_SubjectRegistInfo(string m_strPersonnel_PersonnelKey = DefaultConfig.EMPTY_GUID, int m_iTraining_SubjectKey = 0, DateTime m_dDateTimeNow = new DateTime(), string value = "", int valu = 0) //, DateTime m_dStartTime = new DateTime(), DateTime m_dEndTime = new DateTime()
        {
            var IQuery = m_data.m_DCSave.Personnel_Personnel_SubjectRegists.Where(tb => tb.Personnel_PersonnelKey.ToString() == m_strPersonnel_PersonnelKey && tb.Training_SubjectKey == m_iTraining_SubjectKey && tb.EndTime > m_dDateTimeNow); // && tb.StartTime >= m_dDateTimeNow // && tb.StartTime == m_dStartTime && tb.EndTime == m_dEndTime
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Personnel_Personnel_SubjectRegist();
                m_bds.Add(Row);
            }
        }
    }
}
